﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Content;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace MenuGame2DXNA
{
    public class TextBox : TextEntity
    {
        KeyboardState oldState;
        Game game;
        public TextBox(Game _game)
            : base(_game.Content)
        {
            game = _game;
        }
        public override void Update(GameTime gameTime, Color color)
        {
          
            KeyboardState keyState = Keyboard.GetState();
            foreach (Keys key in keyState.GetPressedKeys())
            {
                if (oldState.IsKeyUp(key))
                {
                    if (key == Keys.Back)
                    {
                        if (Text.Length > 0)
                            Text = Text.Remove(Text.Length - 1, 1);
                    }
                    else if (key == Keys.Enter)
                    {

                        Score sh = new Score(Text, game.ScorePlayer);
                        HighScoreDAL.addScore(sh);
                        game.Scene = 5;
                    }
                    else if(Text.Length < 15)
                    {
                        if (key >= Keys.A && key <= Keys.Z)
                            Text += key.ToString();
                        else if (key == Keys.Space)
                            Text += " ";
                    }
                }
            }
            oldState = keyState;

        }
        
    }
}
